﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using Infrastructure;


namespace OpenAuth.App
{
    public class BMZXX001App : ApiBaseApp<BMZXX001>
    {
      
        public BMZXX001App(IApiRepository<BMZXX001> repository) : base(repository)
        {
        }
        /// <summary>
        ///  首诊患者建档
        /// </summary>
        /// <param name="model">传入的门诊患者信息</param>
        /// <returns></returns>
        public IEnumerable<BMZXX001Response> PutBMZXX001(BMZXX001 model)
        {
            List<SqlParameter> param = new List<SqlParameter>();
            param.Add(new SqlParameter("@Hzxm", model.hzxm));
            param.Add(new SqlParameter("@Sex", model.sex));
            param.Add(new SqlParameter("@Zjh", model.zjh));
            param.Add(new SqlParameter("@Birth", model.birth));
            param.Add(new SqlParameter("@Lxdh", model.lxdh));
            param.Add(new SqlParameter("@Lxdz", model.lxdz));
            //param.Add(new SqlParameter("@Memo", model.memo));
            //param.Add(new SqlParameter("@Lxrxm", model.lxrxm));
            //param.Add(new SqlParameter("@Lxrdh", model.lxrdh));
            param.Add(new SqlParameter("@Lxrzjh", model.lxrzjh));
            //param.Add(new SqlParameter("@Zydm", model.zydm));
            //param.Add(new SqlParameter("@Mzdm", model.mzdm));
            //param.Add(new SqlParameter("@Ybrc", model.ybrc));为空
            param.Add(new SqlParameter("@Czyh", "hf001"));
            string sql = "@hzxm=@Hzxm,@sex=@Sex,@zjh=@Zjh,@birth=@Birth,@lxdh=@Lxdh,@lxdz=@Lxdz,@lxrzjh=@Lxrzjh,@czyh=@Czyh";       
            var result = Put($"exec usp_web_webtrans_BMZXX001 {sql}", param);
            List<BMZXX001Response> list = new List<BMZXX001Response>();
            //返回成功结果
            if (result!=null&&result.Rows[0][0].ToString()=="T")
            {
                list.Add(new BMZXX001Response { patid = result.Rows[0][1].ToString(), blh = result.Rows[0][2].ToString() });
            }
            //返回错误结果
            else
            {
                list.Add(new BMZXX001Response { Code=400,Message=result.Rows[0][1].ToString() });
            }

            return list.AsEnumerable<BMZXX001Response>();
        }
    }
}
